//
//  CustomBottomToolView.m
//  DrivingQuestionBank
//
//  Created by 上榜 on 2024/1/6.
//

#import "CustomBottomToolView.h"


@interface CustomBottomToolView ()
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UIButton *nextBtn;         // 下一个
@property (nonatomic, strong) UIButton *previousBtn;     // 上一个
@property (nonatomic, strong) UILabel *currentNumLabel;  // 1
@property (nonatomic, strong) UILabel *totalNumLabel;    // 199
@property (nonatomic, strong) UILabel *slashLabel;       // /

@end

@implementation CustomBottomToolView

- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self createCustomToolViewUI];
    }
    return self;
}

- (void)createCustomToolViewUI {
    _bgView = [[UIView alloc]init];
    //_bgView.backgroundColor = [UIColor redColor];
    [self addSubview:self.bgView];
    
    _lineView = [[UIView alloc]init];
    _lineView.backgroundColor = [UIColor lightGrayColor];
    [self.bgView addSubview:self.lineView];
    
    _currentNumLabel = [[UILabel alloc] init];
    _currentNumLabel.font = SYSTEM_FONT(15);
    _currentNumLabel.textColor = DQBRGBHex(0x333333);
    _currentNumLabel.textAlignment = NSTextAlignmentCenter;
    [self.bgView addSubview:self.currentNumLabel];
    
    _slashLabel = [[UILabel alloc] init];
    _slashLabel.font = SYSTEM_FONT(15);
    _slashLabel.textColor = DQBRGBHex(0x333333);
    _slashLabel.textAlignment = NSTextAlignmentCenter;
    _slashLabel.text = @"/";
    [self.bgView addSubview:self.slashLabel];
    
    _totalNumLabel = [[UILabel alloc] init];
    _totalNumLabel.font = SYSTEM_FONT(15);
    _totalNumLabel.textColor = DQBRGBHex(0x333333);
    _totalNumLabel.textAlignment = NSTextAlignmentCenter;
    _totalNumLabel.text = @"1999";
    [self.bgView addSubview:self.totalNumLabel];
    
    _previousBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_previousBtn setTitle:@"上一题" forState:UIControlStateNormal];
    [_previousBtn setTitleColor:DQBRGBHex(0x333333) forState:UIControlStateNormal];
    [_previousBtn setTitleColor:DQBRGBHex(0x333333) forState:UIControlStateSelected];
    _previousBtn.titleLabel.font = SYSTEM_FONT(15);
    [_previousBtn addTarget:self action:@selector(clickPreviousEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.previousBtn];
    
    _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_nextBtn setTitle:@"下一题" forState:UIControlStateNormal];
    [_nextBtn setTitleColor:DQBRGBHex(0x333333) forState:UIControlStateNormal];
    [_nextBtn setTitleColor:DQBRGBHex(0x333333) forState:UIControlStateSelected];
    _nextBtn.titleLabel.font = SYSTEM_FONT(15);
    [_nextBtn addTarget:self action:@selector(clickNextEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.bgView addSubview:self.nextBtn];
    
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(0);
        
    }];
    
    [self.currentNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(40);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
    }];
    
    [self.slashLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.currentNumLabel.mas_right);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(20);
    }];
    
    [self.totalNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.slashLabel.mas_right);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
    }];
    
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(22);
        make.width.mas_equalTo(1);
        //make.left.mas_equalTo(Screen_width(130));
        make.left.mas_equalTo(self.totalNumLabel.mas_right).offset(Screen_width(30));
    }];
    
    [self.nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-40);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(54);
        make.width.mas_equalTo(Screen_width(55));
        
    }];
    
    [self.previousBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.nextBtn.mas_left).offset(-40);
        make.centerY.mas_equalTo(self.bgView.mas_centerY);
        make.height.mas_equalTo(54);
        make.width.mas_equalTo(Screen_width(55));
    }];
    
}

- (void)setCurrentNum:(NSString *)currentNum{
    _currentNum = currentNum;
    self.currentNumLabel.text = _currentNum;
}

- (void)setTotalNum:(NSString *)totalNum{
    _totalNum = totalNum;
    self.totalNumLabel.text = _totalNum;
}

// 下一题
- (void)clickNextEvent:(UIButton *)btn{
    DTBLOCK_EXEC(self.clickNextBlock,);
}

// 上一题
- (void)clickPreviousEvent:(UIButton *)btn{
    DTBLOCK_EXEC(self.clickPreviousBlock,);
}

@end
